package com.yunxiao.cloud.job.task;

import com.yunxiao.cloud.job.service.ScheduleJobLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.Date;

/**
 * @description: ScheduleJobLogTask
 * 定时清理日志表
 * @author: yunxiao
 * @date: 2020/1/20 13:20
 * @version: V1.0
 **/
//@Component
public class ScheduleJobLogTask {

    private static final Logger logger = LoggerFactory.getLogger(ScheduleJobLogTask.class);

    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    @Autowired
    private ScheduleJobLogService scheduleJobLogService;

    @Scheduled(initialDelay = 5000, cron = "0 0 2 1/10 * ?")
    public void executeJobLog() {
        try {
            threadPoolTaskExecutor.execute(() -> {
                Date date = new Date();

                scheduleJobLogService.deleteByTime(new Date());
            });
        } catch (Exception e) {
            logger.error("定时清理ScheduleJobLog 失败", e);
        }

    }
}
